<template>
  <div>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">窗口收费</i>
    </div>
    <el-divider></el-divider>
    <h3 align="left">患者信息查询</h3>
    <el-row>
      <el-col :span="8" align="left">
        <div>
          <i class="el-icon-tickets">病历号：</i>
          <el-input style="width:350px" v-model="case_number" placeholder="请输入病历号"></el-input>
        </div>
      </el-col>
      <el-col :span="8" align="left">
        <div>
          <i class="el-icon-user">患者名：</i>
          <el-input style="width:350px" v-model="real_name" placeholder="请输入患者名"></el-input>
        </div>
      </el-col>
      <el-col :span="8" align="left">
        <el-button type="primary" @click="searchPatient()">搜索</el-button>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <h3 align="left">患者信息确认</h3>
    <el-row>
      <el-col :span="6" align="left">
        <div>
          <i class="el-icon-user">患者名：</i>
          <el-input style="width:200px" disabled v-model="patient.real_name" ></el-input>
        </div>
      </el-col>
      <el-col :span="6" align="left">
        <div>
          <i class="el-icon-postcard">身份证号：</i>
          <el-input style="width:200px" disabled v-model="patient.card_number" ></el-input>
        </div>
      </el-col>
      <el-col :span="6" align="left">
        <div>
          <i class="el-icon-date">年龄：</i>
          <el-input style="width:200px" disabled v-model="patient.age" ></el-input>
        </div>
      </el-col>
      <el-col :span="6" align="left">
        <div>
          <i class="el-icon-male">性别：</i>
          <el-input style="width:100px" disabled v-model="patient.gender" ></el-input>
        </div>
      </el-col>
    </el-row>

    <div align="left" style="margin-top:10px">
      <el-button type="primary" style="width:200px" disabled icon="el-icon-price-tag">项目金额：{{total_price}}元</el-button>
      <el-button type="primary" icon="el-icon-price-tag" @click="expenseCharge()">收费结算</el-button>
    </div>
    <el-table style="margin-top:10px;width:90%" :data="price_project_table" @selection-change="priceSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="item_name" label="项目名称" ></el-table-column>      
      <el-table-column prop="item_price" label="单价" width="80"></el-table-column>
      <el-table-column prop="item_type" label="类型" width="80"></el-table-column>
      <el-table-column prop="item_format" label="规格" width="200"></el-table-column>
      <el-table-column prop="item_number" label="数量" width="80"></el-table-column>
      <el-table-column prop="item_create_time" label="开立时间" width="200"></el-table-column>
    </el-table>
    
  </div>
</template>
<script>
export default{
  methods:{
    //收费
    expenseCharge(){
      this.$confirm("本次收费金额为："+this.total_price,"收费窗口",{
        confirmButtonText:"收费",
        cancelButtonText:"取消",
      }).then(()=>{
        this.$http.post("http://localhost:8092/expenseCharge",this.expense_charge_select).then(          
          (resp)=>{
            this.$message({
              type:"success",
              message:resp.data.msg,              
            });
            this.searchPatient();
          });
      }).catch((e)=>{
        console.log(e);
        this.$message({
          type:"info",
          message:"取消收费",
        })
      })
    },
    //根据病历号或者姓名进行搜索患者信息（主要根据：病历号 进行搜索）
    searchPatient(){
      this.$http.get("http://localhost:8092/searchExpenseChargePatient?case_number="+this.case_number+"&real_name="+this.real_name).then(
        (resp)=>{
          this.patient = resp.data.registMap;
          if(this.patient==null){
            this.$message({
              message:"用户不存在，请使用默认病历号 1000009 查询",
              type:"error"
            })
            this.patient = {};
          }
          this.price_project_table =resp.data.requestList;
          this.math_total_price(this.price_project_table);
        }
      )
    },
    priceSelectionChange(val){
      this.expense_charge_select = val;
      this.math_total_price(val);
    },
    math_total_price(total){
      if(total == null){
        total = [];
      }
      this.total_price = 0;
      for(let i=0;i<total.length;i++){
        if(typeof total[i].item_number == "undefined" || total[i].item_number==null || total[i].item_number == ""){
          this.total_price = this.total_price + parseFloat(total[i].item_price)
        }else{
          this.total_price = this.total_price + parseFloat(total[i].item_price)*parseInt(total[i].item_number)
        }            
      }
      this.total_price = this.total_price.toFixed(2);
    }
  },
  data(){
    return {
      expense_charge_select:[],
      patient:{},
      price_project_table:[],
      total_price:0,
      case_number:'',
      real_name:''
    }
  }
}
</script>

